<template>
<!-- 添加商品信息 -->
    <div>
        <el-page-header content="修改视频" @back="goBack">
        </el-page-header>
        <el-row>
            <el-col :span="20">
                <el-input v-model="input" placeholder="请输入视频id"></el-input>
            </el-col>
            <el-col :span="2">
                <el-button icon="el-icon-search" circle @click="searchVideo"></el-button>
            </el-col>
        </el-row>

      <el-form ref="form" :model="video" label-width="80px" v-if="flag">
        <el-form-item label="视频标题">
          <el-input v-model="video.title"></el-input>
        </el-form-item>
        <el-form-item label="视频路径">
          <el-input v-model="video.url"></el-input>
        </el-form-item>
        <el-form-item label="视频类型">
          <el-select v-model="video.class_id" placeholder="请选择">
            <el-option :label="c.name" :value="c.id" v-for="c in classify" :key="c.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <!-- <el-button style="margin-top: 12px;" @click="next">下一步</el-button> -->
          <el-button type="primary" @click="onSubmit">立即操作</el-button>
          <el-button @click="cancel">取消</el-button>
        </el-form-item>
      </el-form>
    </div>
</template>

<script>
export default {
  data(){
    return {
      video:{
          id:"",
          title:"",
          url:"",
          class_id:""
      },
      classify:[],
      input:'',
      flag:false
    }
  },
  methods:{
    searchVideo(){
        if(this.input.trim()!=""){
            if(parseInt(this.input)){
                this.$ajax({
                    url:"admin/getVideoById",
                    method:"get",
                    params:{vid:this.input}
                }).then(resp=>{
                    this.video = resp.data.video[0];
                    this.classify = resp.data.classify;
                    this.flag = true;
                })
            }else{
                this.$message({
                    message: '请输入正确视频id！',
                    type: 'warning'
                });
            }
        }else{
            this.$message({
                message: '输入视频id值不能为空！',
                type: 'warning'
            });
        }
    },
    onSubmit() {
      this.$ajax({
        url:"admin/updtaeVideo",
        method:"post",
        data:this.video
      }).then(resp=>{
        this.$message({
          message: '修改成功',
          type: 'success'
        });
        this.flag = false;
      })
    },
    goBack() {
      this.$router.push("/")
    },
    cancel(){
        this.flag = false;
        this.input='';
    }
  },
  created(){
    
  }
}
</script>

<style scoped>

</style>